#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

string getLongest(string& s1, string& s2)
{
    if (s1.size() > s2.size())
        swap(s1, s2);
    int n = s1.size();
    int m = s2.size();
    vector<vector<int>> vv(n + 1, vector<int>(m + 1, 0));
    int start = 0;
    int max_size = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (s1[i - 1] == s2[j - 1])
                vv[i][j] = vv[i - 1][j - 1] + 1;
            if (vv[i][j] > max_size)
            {
                max_size = vv[i][j];
                start = i - max_size;
            }
        }
    }
    return s1.substr(start, max_size);
}
int main() {
    string s1, s2;
    while (cin >> s1 >> s2)
    {
        cout << getLongest(s1, s2) << endl;
    }
    return 0;
}